package net.zjitc.service.impl;

import net.zjitc.dao.ProductDao;
import net.zjitc.dao.impl.ProductDaoImpl;
import net.zjitc.domain.Product;
import net.zjitc.service.ProductService;
import net.zjitc.utils.PageBean;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;

/**
 * 2 * @Author: 洪瑶
 * 3 * @Date: 2018/10/16 15:59
 * 4
 */
public class ProductServiceImpl implements ProductService {
    ProductDao dao = new ProductDaoImpl();

    @Override
    public List<Product> findAll() throws SQLException {
        return dao.sqlfindAll();
    }

    @Override
    public List<Product> findhot() throws SQLException {
        return dao.sqlfindhot();
    }

    @Override
    public List<Product> findnew() throws SQLException {
        return dao.sqlfindnew();
    }

    @Override
    public boolean Add(Product product) throws SQLException {
        product.setPdate(new Date());
        product.setCsid(1);
        return dao.sqlAdd(product);
    }

    @Override
    public boolean Delete(int id) throws SQLException {
        return dao.sqlDelete(id);
    }

    @Override
    public boolean Update(Product product, String id) throws SQLException {
        return dao.sqlUpdate(product,id);
    }

    @Override
    public Product findbyid(int id) throws SQLException {
        return dao.sqlfindbyid(id);
    }

    @Override
    public PageBean<Product> findbyPage(int page, int pageSize) {
        PageBean<Product> pageBean = new PageBean<>();
        pageBean.setPage(page);
        pageBean.setPageSize(pageSize);
        List<Product>list = dao.findPageList(page,pageSize);
        pageBean.setPageList(list);
        int count = dao.findcount();
        pageBean.setCount(count);
        return pageBean;
    }

    @Override
    public List<Product> findCategoryPageList(int cid, int page, int pageSize) throws SQLException {
        return dao.findCategoryPageList(cid,page,pageSize);
    }

    @Override
    public int findcount() {
        return dao.findcount();
    }

    @Override
    public List<Product> findCategorySecondPageList(int csid, int page, int pageSize) throws SQLException {
        return dao.findCategorySecondPageList(csid,page,pageSize);
    }


}
